package com.itheima.service.impl;

import com.itheima.service.FileService;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.UUID;

@Service
public class FileServiceImpl implements FileService {


    public String saveFile(MultipartFile file) throws IOException {

        String originalFilename = file.getOriginalFilename();
        String[] arr = originalFilename.split("\\.");
        String ext=arr[arr.length-1];
        String newName=UUID.randomUUID().toString()+"."+ext;
        File file1 = new File("D://a//" + newName);
        file.transferTo(file1);
        return file1.getAbsolutePath();
    }
}
